package com.nb.sse.controller;

import cn.hutool.json.JSONUtil;
import com.nb.sse.entity.SysNotice;
import com.nb.sse.model.UnReadMsgVO;
import com.nb.sse.service.ISysNoticeService;
import com.nb.sse.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lihaoyang6
 * @date 2024年07月14日 16:33
 */
@RequestMapping
@RestController
public class MsgController {

    @Autowired
    ISysNoticeService sysNoticeService;


    @Autowired
    MessageService messageService;



    @GetMapping("saveMsg")
    public String saveMsg(Integer userId,String msg){
        SysNotice notice = new SysNotice();
        notice.setTitle(msg);
        notice.setMsgContent(msg);
        notice.setReadFlag(0);
        notice.setReceiverUserId(userId);
        sysNoticeService.save(notice);
        int count = sysNoticeService.countUnReadByUserId(userId);
        //发布
        UnReadMsgVO msgVO = new UnReadMsgVO();
        msgVO.setUserId(userId);
        msgVO.setCount(count);
        messageService.publish(msgVO);

        return "SUCCESS";
    }
}
